<template>
	<!-- 机加开料页面 -->
	<div>
		<v-container row class="text-subtitle-1 d-flex justify-center  align-left">
			<v-row class="mt-2">
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目号" v-model="queryChildren.projectCode" placeholder="项目号" dense outlined>
					</v-text-field>
				</v-col>
				<!-- sm="6" md="2" -->
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目名称" v-model="queryChildren.projectName" placeholder="项目名称" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="设备名称" v-model="queryChildren.equipmentName" placeholder="设备名称" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="2" md="2">
					<v-text-field label="工单号" v-model="queryChildren.childrenCode" placeholder="工单号" dense outlined>
					</v-text-field>
				</v-col>
				<!-- ml-n16 前面加n是间距 -->
				<!-- class="ml-n16 mx-auto" -->
				<v-col cols="12" sm="2" md="2">
					<v-btn depressed color="primary" @click="search">查询</v-btn>
					<v-btn class="ml-3" depressed color="primary" @click="refreshApps">
						刷新</v-btn>
				</v-col>
			</v-row>

		</v-container>

		<br />

		<v-card class="pa-4" justify="space-between">
			<v-sheet class="pa-12" color="grey lighten-3">
				<v-btn color="primary" @click="openTheMaterialDialog">开料</v-btn>
				<v-tooltip bottom>
					<template v-slot:activator="{ on, attrs }">
						<v-btn color="primary" :disabled="!isSendEmailBtn" class="ml-3" v-bind="attrs" v-on="on"
							@click="openEmailDialog">
							邮件发送</v-btn>
					</template>
					<span>选中下方需要发送邮件的开料信息</span>
				</v-tooltip>
				<v-tooltip bottom>
					<template v-slot:activator="{ on, attrs }">
						<v-btn color="primary" :disabled="!isDownCutDetailBtn" class="ml-3" v-bind="attrs" v-on="on"
							@click="exportExcel">
							导出Excel
						</v-btn>
					</template>
					<span>选中下方需要导出开料信息</span>
				</v-tooltip>
			</v-sheet>
			<v-tabs color="red">
				<v-tab @change="isSendEmailBtn=false,isDownCutDetailBtn=false,currentTabIndex=0">
					工单与开料对应信息
				</v-tab>
				<v-tab @change="isSendEmailBtn=true,isDownCutDetailBtn=true,currentTabIndex=1">
					所有开料信息
				</v-tab>
				<!-- 工单与开料对应信息 -->
				<v-tab-item>
					<v-row>
						<v-col cols="8">
							<v-data-table small dense :headers='[{"text":"工单号","value":"code"},
										{"text":"名称","value":"name"},
										{"text":"项目号","value":"projectcode"}
										]' :items="childrenOrderList" item-key="id" class="text-no-wrap" show-select :single-select="true"
								:loading="childrenOrderLoading" :options.sync="childrenOrderOptions"
								:footer-props="vuetifyDefaultPage" :server-items-length="childrenOrderTotalCount"
								@item-selected="leftChildrenOrderCheckEvent">
							</v-data-table>
						</v-col>
						<v-col cols="4">
							<p v-if="rightcutDetailList.length==0">请选中左侧的子工单信息</p>
							<v-simple-table v-else dense>
								<template v-slot:default>
									<thead>
										<tr>
											<th class="text-center text-no-wrap">
												选项
											</th>
											<th class="text-center text-no-wrap">
												操作
											</th>
											<th class="text-left text-no-wrap">
												存货大类名称
											</th>
											<th class="text-left text-no-wrap">
												存货名称
											</th>
											<th class="text-left text-no-wrap">
												材质
											</th>
											<th class="text-left text-no-wrap">
												规格
											</th>
											<th class="text-left text-no-wrap">
												密度
											</th>
											<th class="text-left text-no-wrap">
												毛坯尺寸(长-宽-高/厚)
											</th>
											<th class="text-left text-no-wrap">
												毛坯重量
											</th>
											<th class="text-left text-no-wrap">
												单位
											</th>
											<th class="text-left text-no-wrap">
												是否采购
											</th>
											<th class="text-left text-no-wrap">
												需求日期
											</th>
											<th class="text-left text-no-wrap">
												用量
											</th>
											<th class="text-left text-no-wrap">
												开料原因名称
											</th>
											<th class="text-left text-no-wrap">
												备注
											</th>
										</tr>
									</thead>
									<tbody>
										<tr v-for="item in rightcutDetailList" :key="item.id">
											<td>
												<v-checkbox v-model="item.cutdetailcheck"></v-checkbox>
											</td>
											<td class="text-left text-no-wrap">
												<v-btn small tile color="green" @click="openEditEveryCutDetail(item)">
													修改
												</v-btn>

												<v-btn class="ml-2" small tile color="primary"
													@click="deleteEveryCutDetail(item)">
													<v-icon small left>
														mdi-wrench
													</v-icon>
													删除
												</v-btn>
											</td>
											<td class="text-left text-no-wrap">{{item.categoryname}}</td>
											<td class="text-left text-no-wrap">{{item.name}}</td>
											<td class="text-left text-no-wrap">{{item.material}}</td>
											<td class="text-left text-no-wrap">{{item.specifications}}</td>
											<td class="text-left text-no-wrap">{{item.density}}</td>
											<td class="text-left text-no-wrap">
												{{item.length+'-'+item.width+'-'+item.height}}
											</td>
											<td class="text-left text-no-wrap">{{item.weight}}</td>
											<td class="text-left text-no-wrap">{{item.unitname}}</td>
											<td class="text-left text-no-wrap">
												{{item.isstandard==null?'':(item.isstandard?"标准原材":"下料原材")}}
											</td>
											<td class="text-left text-no-wrap">{{item.needdate}}</td>
											<td class="text-left text-no-wrap">{{item.useqty}}</td>
											<td class="text-left text-no-wrap">{{item.cuttingwhytypename}}</td>
											<td class="text-left text-no-wrap">{{item.description}}</td>
										</tr>
									</tbody>
								</template>
							</v-simple-table>
						</v-col>
					</v-row>
				</v-tab-item>
				<!-- 开料信息 -->
				<v-tab-item>
					<v-data-table :headers="cuttingDetailHeaderList" :items="cuttingDetailDataList" small fixed-header
						item-key="id" dense class="text-no-wrap" show-select loading-text="正在加载请稍等......"
						:loading="cuttingDetailLoading" :options.sync="cuttingDetailOptions"
						:footer-props="vuetifyDefaultPage" :server-items-length="cuttingDetailTotalCount"
						@input="selectCuttingDetailMultiple">
						<template v-slot:item.isprocurement="{ item }">
							<a v-if="item.isprocurement==1" style="color: #67C23A;">是</a>
							<a v-else>否</a>
						</template>

						<template v-slot:item.issendemail="{ item }">
							<a v-if="item.issendemail==1" style="color: #67C23A;">是</a>
							<a v-else>否</a>
						</template>
					</v-data-table>
				</v-tab-item>
			</v-tabs>
		</v-card>




		<!-- 开料对话框 -->
		<v-dialog v-model="openMaterialDialogVisable" fullscreen transition="dialog-bottom-transition">
			<v-card>
				<v-toolbar dark color="primary">
					<v-btn icon dark @click="openMaterialDialogVisable = false">
						<v-icon>mdi-close</v-icon>
					</v-btn>
					<v-toolbar-title>工单开料</v-toolbar-title>
					<v-spacer></v-spacer>
				</v-toolbar>
				<v-row>
					<v-col cols="4">
						<v-alert text color="blue-grey" class="text-center">开料基础信息维护 <a style="color: red;"
								class="ml-1">注意：开料原因必选，右侧拼料子工单必选！</a>
						</v-alert>
						<v-card>
							<v-card-text>
								<v-row>
									<v-col cols="12" md="12">
										<v-row>
											<v-col cols="12" md="9">
												<v-text-field :style="this.tempcutDetailDialogFrom.name" disabled dense
													outlined v-model="cutDetailDialogFrom.name" label="选择存货(必选)">
												</v-text-field>
											</v-col>
											<v-col cols="12" md="3">
												<v-btn color="primary" @click="eidtInventoryClcik">
													选择原材信息
												</v-btn>
											</v-col>
										</v-row>

									</v-col>
									<v-col cols="12" md="12">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.specifications"
											label="规格">
										</v-text-field>
									</v-col>
									<v-col cols="12" md="6">
										<v-select dense outlined v-model="cutDetailDialogFrom.unitname"
											:items="unitTypeEnumList" label="单位">
										</v-select>
									</v-col>

									<v-col cols="12" md="6">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.useqty"
											label="用量(必填)">
										</v-text-field>
									</v-col>

									<v-col cols="12" md="6">
										<v-menu v-model="cutDetailDialogFromNeedDateMenu"
											:close-on-content-click="false" :nudge-right="40"
											transition="scale-transition" offset-y min-width="auto">
											<template v-slot:activator="{ on, attrs }">
												<v-text-field dense outlined required
													v-model="cutDetailDialogFrom.needdate" label="需求日期" readonly
													v-bind="attrs" v-on="on"></v-text-field>
											</template>
											<v-date-picker locale="zh-cn" v-model="cutDetailDialogFrom.needdate"
												@input="cutDetailDialogFromNeedDateMenu = false"></v-date-picker>
										</v-menu>

									</v-col>
									<v-col cols="12" md="6">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.material" label="材质">
										</v-text-field>
									</v-col>

									<v-col cols="12" md="4">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.length" label="长">
										</v-text-field>
									</v-col>
									<v-col cols="12" md="4">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.width" label="宽">
										</v-text-field>
									</v-col>
									<v-col cols="12" md="4">
										<v-text-field dense outlined v-model="cutDetailDialogFrom.height" label="高">
										</v-text-field>
									</v-col>

									<v-col cols="12" md="12">
										<v-select dense outlined v-model="cutDetailDialogFrom.cuttingwhytype"
											:items="cuttingwhyTypeEnumList" label="开料原因(必选)"></v-select>
									</v-col>
									<!-- 	<v-col cols="12" md="6">
								<v-checkbox dense outlined v-model="cutDetailDialogFrom.isprocurement" label="是否采购">
								</v-checkbox>
							</v-col> -->
									<v-col cols="12">
										<v-textarea outlined name="input-7-4" label="备注"
											v-model="cutDetailDialogFrom.description"
											:value="cutDetailDialogFrom.description">
										</v-textarea>
									</v-col>
								</v-row>
							</v-card-text>

							<v-card-actions class="text-center">
								<v-spacer></v-spacer>
								<v-btn tile :color="dialogFromSubmitBtn.color"
									:disabled="!cutDetailDialogFrom.cuttingwhytype" @click="addOrEditcutDetailSubmit">
									{{dialogFromSubmitBtn.text}}
								</v-btn>
								<v-btn color="secondary" tile dark @click="openMaterialDialogVisable=false">
									取消
								</v-btn>

							</v-card-actions>
						</v-card>
					</v-col>
					<v-col cols="4">
						<v-alert text color="blue-grey" class="text-center">拼料子工单 </v-alert>
						<v-card height="800">
							<v-card-text>
								<v-row>
									<v-col cols="12" md="6">
										<v-text-field label="项目号" v-model="queryChildren.projectCode" placeholder="项目号"
											dense outlined>
										</v-text-field>
									</v-col>
									<!-- sm="6" md="2" -->
									<v-col cols="12" md="6">
										<v-text-field label="项目名称" v-model="queryChildren.projectName"
											placeholder="项目名称" dense outlined>
										</v-text-field>
									</v-col>
									<v-col cols="12" md="4">
										<v-text-field label="设备名称" v-model="queryChildren.equipmentName"
											placeholder="设备名称" dense outlined>
										</v-text-field>
									</v-col>
									<v-col cols="12" md="4">
										<v-text-field label="工单号" v-model="queryChildren.childrenCode" placeholder="工单号"
											dense outlined>
										</v-text-field>
									</v-col>

									<v-col cols="12" md="2">
										<v-btn color="primary" @click="search">查询</v-btn>
									</v-col>

									<v-col cols="2" align="end">
										<v-btn dark color="blue lighten-3" @click="refreshApps">
											<v-icon dark>mdi-refresh-circle</v-icon>刷新
										</v-btn>
									</v-col>
								</v-row>
								<v-data-table small dense :headers='childrenHeaderList' :items="childrenOrderList"
									item-key="id" class="text-no-wrap" show-select :loading="childrenOrderLoading"
									:options.sync="childrenOrderOptions" :footer-props="vuetifyDefaultPage"
									:server-items-length="childrenOrderTotalCount"
									@input="cutDetailChildrenSelectEvent">
								</v-data-table>
							</v-card-text>
						</v-card>
					</v-col>
					<v-col clos="4">
						<v-alert text color="blue-grey" class="text-center">图纸预览</v-alert>

						<v-card height="800">
							<v-card-text>
								<pdf v-if="cutDetailDialogFromImageItem!=null" ref="pdf"
									src="http://localhost:9866/src/pdffile/073016480144ImagePDF.pdf"></pdf>
								<!-- <v-img v-if="cutDetailDialogFromImageItem!=null" max-width="700"
								:src="cutDetailDialogFromImageItem.picurl"></v-img> -->
								<p v-else>请选中一条子工单信息</p>
							</v-card-text>
						</v-card>
					</v-col>
				</v-row>

				</v-list>

			</v-card>
		</v-dialog>

		<!-- 大图弹出对话框 -->
		<v-dialog v-if="cutDetailDialogFromImageItem!=null" v-model="bigPicDialogVisable" max-width="1000px">
			<v-card>
				<v-card-title>
					{{cutDetailDialogFromImageItem.piccode}}
				</v-card-title>
				<v-card-text>
					<v-img v-if="cutDetailDialogFromImageItem!=null" :src="cutDetailDialogFromImageItem.picurl"></v-img>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="primary" text @click="bigPicDialogVisable = false">
						关闭
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 发送邮件对话框 -->
		<email :emailModel="emailModel" :callBack="callBackLoadCuttingDetailList"></email>
		<inventorycomment :materialComment="materialComment" :setMaterialcallBack="setMaterialcallBack">
		</inventorycomment>
	</div>
</template>

<script>
	import inventorycomment from '../../pdm/components/InventoryDataList.vue'
	import pdf from 'vue-pdf'
	import email from '../components/SendEmail.vue'
	export default {
		name: 'mes_production_putcost_steel',
		components: {
			pdf,
			email,
			inventorycomment
		},
		data: () => ({
			materialComment: {
				dialog: false,
				loadInventoryPageUrl: `MES/MESCutDetail/GetERPMaterialTypeList`,
				loadInventoryClassUrl: `MES/MESCutDetail/loadInventoryClass`,
				loadUnitsUrl: `MES/MESCutDetail/loadUnits`,
				addInventoryUrl: `MES/MESCutDetail/AddInventory`,
				queryInvClassTreeUrl: `MES/MESCutDetail/GetInvclassTree?iinvcgrade=`

			},
			emailModel: {
				sendEmailDialogVisable: false,
				queryIds: [],
				GetDepartmentUserToSelectUrl: '',
				SendEmailUrl: ''
			},
			addCutDetailList: [],
			queryChildren: {
				projectCode: '',
				projectName: '',
				equipmentName: '',
				childrenCode: ''
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			childrenOrderLoading: true,
			childrenOrderTotalCount: 0,
			childrenOrderOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			sendEmailDialogVisable: false,
			bigPicDialogVisable: false,
			selectedInputType: null,
			searchInput: null,
			childrenHeaderList: [],
			childrenOrderList: [],
			tempChildrenOrderList: [],
			checkChildrenIds: [],
			//右侧的开料信息
			rightcutDetailList: [],
			tempRightCutDetailList: [],
			cutDetailDialogFrom: {},
			tempcutDetailDialogFrom: {},
			blankTypeEnumList: [],
			blankChildrenTypeEnumList: [],
			tempChildrenEnumList: [],
			cuttingwhyTypeEnumList: [],
			unitTypeEnumList: [],
			paramterEnums: ['BlankType', 'BlankChildrenType', 'CuttingwhyType', 'UnitType'],
			//开料对话框
			openMaterialDialogVisable: false,
			cutDetailDialogFromNeedDateMenu: false,
			cutDetailDialogFromImageItem: null,
			//开料名称绑定v-commbox
			childrentype: null,
			addOrEditButton: [{
				text: '新增',
				value: 0,
				color: 'success'
			}, {
				text: '修改',
				value: 1,
				color: 'red'
			}],
			dialogFromSubmitBtn: null,
			tempReceiveUserList: [],
			emailView: {
				title: '',
				body: '',
				isAttachmentInfo: false,
				receiveIfnos: [],
				querInfo: {
					queryIds: []
				}
			},
			cutdetailPagination: {
				totalPages: 0,
				pageNumber: 1,
				pageSize: 10
			},
			isSendEmailBtn: false,
			isDownCutDetailBtn: false,
			//开料页签
			currentTabIndex: 0,
			checkCuttingDetailList: [],
			cuttingDetailHeaderList: [],
			cuttingDetailDataList: [],
			cuttingDetailLoading: true,
			cuttingDetailTotalCount: 0,
			cuttingDetailOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
		}),
		created() {
			this.selectedInputType = null
			this.searchInput = null
			this.loadEnumList()
			this.loadMaterialEnumList()
			this.loadHeaderList()
			this.dialogFromSubmitBtn = this.addOrEditButton[0]
		},
		watch: {
			childrenOrderOptions: {
				handler() {
					this.search()
				},
				deep: true
			},
			cuttingDetailOptions: {
				handler() {
					this.loadCuttingDetailList()
				},
				deep: true
			},
		},
		methods: {

			async cutdetailDialogPage(pageNumber) {
				var response = await this.query(pageNumber, this.cutdetailPagination.pageSize)
				if (response.status == 1) {
					this.childrenOrderList = response.data.childrenList
					this.cutdetailPagination.totalPages = response.data.totalPages
				}
			},
			openEmailDialog() {
				this.emailModel.sendEmailDialogVisable = true
				this.emailModel.queryIds = this.checkCuttingDetailList.map(r => r.id)
				this.emailModel.GetDepartmentUserToSelectUrl = `MES/MESCutDetail/GetDepartmentUserToSelect`
				this.emailModel.SendEmailUrl = `MES/MESCutDetail/SendEmail`
			},
			//邮件发送完成后的回调函数
			callBackLoadCuttingDetailList() {
				this.loadCuttingDetailList()
			},

			refreshApps() {
				this.queryChildren = {
					projectCode: '',
					projectName: '',
					equipmentName: '',
					childrenCode: ''
				}
			},

			async loadMaterialEnumList() {
				var response = await this.$httpRequest({
					url: `MES/MESCutDetail/loadUnits`,
					method: 'get',
				})
				if (response.status == 1) {
					this.unitTypeEnumList = response.data
				}
			},
			loadEnumList() {
				var that = this
				this.$httpRequest({
					url: `MES/MESCommon/GetTypes`,
					method: 'post',
					data: this.paramterEnums
				}).then(function(response) {
					if (response.status == 1) {
						response.data.find(function(e) {
							if (e.enumName == that.paramterEnums[0]) {
								// that.blankTypeEnumList.push(e)
							}
							if (e.enumName == that.paramterEnums[1]) {
								// that.blankChildrenTypeEnumList.push(e)
								// that.tempChildrenEnumList.push(e)
							}
							if (e.enumName == that.paramterEnums[2]) {
								that.cuttingwhyTypeEnumList.push(e)
							}
							if (e.enumName == that.paramterEnums[3]) {
								// that.unitTypeEnumList.push(e)
							}
						})

					} else {
						that.$message.error('加载配置信息失败')
					}
				})
			},
			//加载开料信息
			loadCuttingDetailList() {
				this.cuttingDetailLoading = true
				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/GetAllCuttingDetails?
					equipmentName=${this.queryChildren.equipmentName}&
					childrenCode=${this.queryChildren.childrenCode}&
					projectCode=${this.queryChildren.projectCode}&
					projectName=${this.queryChildren.projectName}&
					pageNumber=${this.cuttingDetailOptions.page}&
					pageSize=${this.cuttingDetailOptions.itemsPerPage}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.cuttingDetailHeaderList = response.data.headers
						that.cuttingDetailDataList = response.data.data.result
						that.cuttingDetailTotalCount = response.data.data.pagination.totalRecords
						that.cuttingDetailLoading = false
					} else {
						that.$message.error('加载开料信息失败')
					}
				})
			},
			//加载子工单信息
			async search() {
				if (this.currentTabIndex == 1) {
					this.loadCuttingDetailList()
					return
				}
				this.childrenOrderLoading = true
				this.childrenOrderList = []
				var response = await this.query(this.childrenOrderOptions.page, this.childrenOrderOptions.itemsPerPage)
				if (response.status == 1) {
					this.childrenOrderList = response.data.childrenList
					this.cutdetailPagination.totalPages = response.data.totalPages
					this.childrenOrderTotalCount = response.data.totalCount.value
					this.childrenOrderLoading = false
				} else {
					this.$message.error('加载子工单失败')
				}

			},

			async query(pageIndex, pageSize) {
				var response = await this.$httpRequest({
					url: `MES/MESCutDetail/LoadChildrenOrderList?
					projectcode=${this.queryChildren.projectCode}&
					projectname=${this.queryChildren.projectName}&
					name=${this.queryChildren.equipmentName}&
					code=${this.queryChildren.childrenCode}&
					type=2&
					pageNumber=${pageIndex}&
					pageSize=${pageSize}`,
					method: 'get'
				})
				return response
			},
			// 每个子工单项点击事件 --获取子工单对应的开料信息
			everyChildrenOrderClik(childrenid) {
				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/GetCuttingDetails/${childrenid}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.rightcutDetailList = response.data

					} else {
						that.$message.error('获取开料信息失败')
					}
				})
			},
			// 左侧子工单勾选事件
			leftChildrenOrderCheckEvent(every) {

				// 	if (!item.check) {
				// 		this.rightcutDetailList.filter(r => r.childrenorderid == item.id).forEach(c => {
				// 			this.rightcutDetailList.splice(this.rightcutDetailList.findIndex(z => z.id == c.id), 1)
				// 		})
				// 		return
				// 	}
				this.rightcutDetailList = []
				if (!every.value) {
					return
				}
				var item = every.item
				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/GetCuttingDetails/${item.id}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						response.data.forEach(r => {
							const detail = that.rightcutDetailList.find(c => {
								return c.id == r.id
							})
							if (detail == null) {
								that.rightcutDetailList.push(r)
							}
						})

					} else {
						that.$message.error('获取开料信息失败')
					}
				})
			},
			async addOrEditcutDetailSubmit() {

				if (this.dialogFromSubmitBtn.value == 0)
					await this.addOpenMaterialSubmit()
				else
					await this.editOpenMaterialSubmit()
			},
			// 工单开料提交
			async addOpenMaterialSubmit() {

				if (this.checkChildrenIds.length <= 0) {
					this.$message.error('请选择右侧子工单！')
					return
				}
				this.addCutDetailList = []
				this.addCutDetailList.push(this.cutDetailDialogFrom)

				var response = await this.$httpRequest({
					url: `MES/MESCutDetail/AddCuttingDetails`,
					method: 'post',
					data: {
						childrenOrderIds: this.checkChildrenIds,
						cutDetails: this.addCutDetailList
					}
				})

				if (response.status == 1) {
					this.everyChildrenOrderClik(this.checkChildrenIds[0])
					this.openMaterialDialogVisable = false
					this.$message.success('添加开料信息成功')
				} else {
					this.$message.error('添加开料信息失败')
				}
			},

			//编辑工单开料提交
			async editOpenMaterialSubmit() {
				var response = await this.$httpRequest({
					url: `MES/MESCutDetail/UpdateCuttingDetails`,
					method: 'put',
					data: this.cutDetailDialogFrom
				})

				if (response.status == 1) {
					this.openMaterialDialogVisable = false
					this.$message.success('修改开料信息成功')
				} else {
					this.$message.error('修改开料信息失败')
				}
			},
			// 开料对话框框勾选每一个子工单事件
			checkCutDetailDialogFromChildrenItem(item) {
				//变更图片的内容 .picurl cutDetailDialogFromImageUrl
				if (item.check)
					this.cutDetailDialogFromImageItem = item
				else
					this.cutDetailDialogFromImageItem = null
			},
			//查看大图
			lookBigPic() {
				this.bigPicDialogVisable = true
			},
			// 开料按钮打开独对话框
			openTheMaterialDialog() {
				this.tempChildrenOrderList = []
				this.openMaterialDialogVisable = true
				this.dialogFromSubmitBtn = this.addOrEditButton.find(r => {
					return r.value == 0
				})
				this.cutDetailDialogFrom = {}
				this.cutDetailDialogFromImageItem = null
				// this.childrenOrderList.forEach(r => {
				// 	console.log(r)
				// 	r.check = false
				// 	r.disabled=false
				// })
			},
			//打开修改开料信息对话框
			openEditEveryCutDetail(item) {
				this.tempChildrenOrderList = []
				this.cutDetailDialogFrom = item
				this.openMaterialDialogVisable = true
				this.dialogFromSubmitBtn = this.addOrEditButton.find(r => {
					return r.value == 1
				})
				this.childrenOrderList.find(r => {
					if (r.id == item.childrenorderid) {
						this.cutDetailDialogFromImageItem = r
						this.tempChildrenOrderList.push(r)
					}
				})
			},

			//删除单个开料信息
			deleteEveryCutDetail(item) {
				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/DeleteCuttingDetails?cutDetailIds=${item.id}`,
					method: 'delete'
				}).then(function(response) {
					if (response.status == 1) {
						that.everyChildrenOrderClik(item.childrenorderid)
						that.$message.success('删除开料信息成功')
					} else {
						that.$message.error('删除开料信息失败')
					}
				})
			},
			//选中多个开料信息事件
			selectCuttingDetailMultiple(mulitple) {
				this.checkCuttingDetailList = mulitple
			},

			Clone(obj) {
				if (obj === null) return null
				if (typeof obj !== 'object') return obj;
				if (obj.constructor === Date) return new Date(obj);
				if (obj.constructor === RegExp) return new RegExp(obj);
				var newObj = new obj.constructor(); //保持继承链
				for (var key in obj) {
					if (obj.hasOwnProperty(key)) { //不遍历其原型链上的属性
						var val = obj[key];
						if (val == null)
							continue;
						newObj[key] = typeof val === 'object' ? arguments.callee(val) : val; // 使用arguments.callee解除与函数名的耦合
					}
				}
				return newObj;
			},
			//选择存货信息
			eidtInventoryClcik() {
				this.materialComment.dialog = true
			},
			setMaterialcallBack(item) {
				this.tempcutDetailDialogFrom = item
				this.cutDetailDialogFrom.categorycode = item.cinvccode
				this.cutDetailDialogFrom.code = item.cinvcode
				this.cutDetailDialogFrom.name = item.cinvname
				this.cutDetailDialogFrom.specifications = item.cinvstd
				this.cutDetailDialogFrom.unitname = item.unitname
			},
			//发送邮件对话框
			sendEmail() {
				// TODO
				var detailIds = this.checkCuttingDetailList.map(r => r.id)
				this.emailView.querInfo.queryIds = detailIds
				this.emailView.isAttachmentInfo = true
				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/SendEmail`,
					method: 'post',
					data: this.emailView
				}).then(function(response) {
					if (response.status == 1) {
						that.sendEmailDialogVisable = false
						that.$message.success(response.info)
						that.loadCuttingDetailList()
					} else {
						that.$message.error(response.info)
					}
				})
			},
			// 导出excel
			exportExcel() {
				var detailIds = this.checkCuttingDetailList.map(r => r.id)

				var that = this
				this.$httpRequest({
					url: `MES/MESCutDetail/ExportExcel`,
					method: 'post',
					data: detailIds,
					responseType: 'blob'
				}).then((response) => {
					that.downloadFile2(response, '开料明细.xls')
				})
				// this.downloadFile(response)
				// this.downloadFile(response, '开料明细.xlsx')
			},
			// 下载文件
			downloadFile(res, fileName) {
				let blob = new Blob([res.data], {
					type: 'application/vnd.ms-excel'
				}); //res为从后台返回的数据
				if (!fileName) {
					fileName = res.headers['Content-Disposition'].split('filename=').pop();
				}
				if ('msSaveOrOpenBlob' in navigator) {
					window.navigator.msSaveOrOpenBlob(blob, fileName);
				} else {
					const elink = document.createElement('a');
					elink.download = fileName;
					elink.style.display = 'none';
					elink.href = URL.createObjectURL(blob);
					document.body.appendChild(elink);
					elink.click();
					URL.revokeObjectURL(elink.href);
					document.body.removeChild(elink);
				}
			},
			downloadFile2(res, name) {
				var blob = new Blob([res], {
					type: 'application/vnd.ms-excel'
				}) // type这里表示xlsx类型
				var downloadElement = document.createElement('a')
				var href = window.URL.createObjectURL(blob) // 创建下载的链接
				downloadElement.href = href
				downloadElement.download = name // 下载后文件名
				document.body.appendChild(downloadElement)
				downloadElement.click() // 点击下载
				document.body.removeChild(downloadElement) // 下载完成移除元素
			},
			cutDetailChildrenSelectEvent(childrens) {
				this.checkChildrenIds = childrens.map(r => r.id)
			},
			loadHeaderList() {
				this.childrenHeaderList = [{
						text: '名称',
						value: 'name',
						align: 'center',
						filterable: true,
					},
					{
						text: '需求数量',
						value: 'totalcount',
						align: 'center',
						filterable: true,
					},
					{
						text: '查看图纸',
						value: 'picurl',
						align: 'center',
						filterable: true,
					},
					{
						text: '交期',
						value: 'deliverydate',
						align: 'center',
						filterable: true,
					},
					{
						text: '项目号',
						value: 'projectcode',
						align: 'center',
						filterable: true,
					},
					{
						text: '项目名称',
						value: 'projectname',
						align: 'center',
						filterable: true,
					},
					{
						text: '类型',
						value: 'typename',
						align: 'center',
						filterable: true,
					},
				]
			},
		}
	}
</script>

<style>
</style>
